<template>
  <div class="recharge">
    <div class="user-account">
      当前账户余额:<span style="color:brown;">{{money}}元</span>
    </div>
    <div class="recharge-card">
      <div class="top">
        <div class="title">优惠券</div>
        <div class="recharge-money">充值：1元</div>
        <div class="send-money">赠送：1000元</div>
      </div>
      <div class="bottom" @click="rechargeMoney">立即充值</div>
    </div>

    <div class="recharge-card">
      <div class="top">
        <div class="title">优惠券</div>
        <div class="recharge-money">充值：1000元</div>
        <div class="send-money">赠送：1元</div>
      </div>
      <div class="bottom" @click="rechargeMoney">立即充值</div>
    </div>
  </div>
</template>

<script>
  import {getUserAccount,recharge} from '@/request/api.js'
export default {
  data(){
    return({
      money:0,
      userId:0,
    })
  },
  mounted(){
    this.userId = JSON.parse(localStorage.getItem('userInfo')).id
    this.getMoney()
  },
  methods:{
    rechargeMoney(){
      recharge({id:this.userId}).then(res=>{
        this.$toast.success(res.message)
        this.getMoney()
      })
    },
    getMoney(){
      getUserAccount({id:this.userId}).then(res=>{
        this.money = res.data
      })
    }
  },
}
</script>

<style scoped>
  .recharge-money,.send-money{
    color:#fff;
    padding:10px;
  }
  .send-money{
    font-size: 20px;
    color:orange;
  }
  .top .title{
    background: #fff;
    height: 40px;
    width:200px;
    color: orange;
    font-size: 18px;
    font-weight: 700;
    transform: rotate(45deg);
    position: absolute;
    right: -66px;
    top: 14px;
    text-align: center;
    line-height: 40px;
  }
  .top::before{
    content: "smile's shop";
    position: absolute;
    top: 50%;
    left:50%;
    transform: translate(-50%,-50%);
    color: lightgray;
    font-size: 28px;
    font-weight: 700;
    opacity: .1;
  }
  .top{
    box-sizing: border-box;
    height: 150px;
    padding:15px;
    background: #f18162;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
  }
  .bottom{
    height: 50px;
    line-height: 50px;
    text-align: center;
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
  }
  .recharge-card{
    margin:20px 0;
    position: relative;
    border-radius: 15px;
    height:200px;
    width:100%;
    border: thin solid #f18162;
    overflow: hidden;
  }
.recharge{
  margin-top: 46px;
  padding:10px;
}
.user-account{
  margin-bottom: 10px;
}
</style>